package com.dg.dto;

import com.dg.common.Const;
import com.dg.pojo.Acl;
import com.dg.pojo.AclModule;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class RoleAclModuleTreeDto {

    private Integer id;

    //权限点id
    private Integer aclId;

    //节点名称
    private String title;

    //排序
    private Integer seq;

    private Integer parentId;

    //是否展开
//    private Boolean expand = true;

    //是否勾选
    private Boolean checked = false;

    //是否禁用
    private Boolean disabled = false;

    private List<RoleAclModuleTreeDto> children = Lists.newArrayList();

    public static RoleAclModuleTreeDto adapter(Acl acl){
        RoleAclModuleTreeDto roleAclModuleTreeDto = new RoleAclModuleTreeDto();
        BeanUtils.copyProperties(acl, roleAclModuleTreeDto);
        roleAclModuleTreeDto.setAclId(acl.getId());
        if(acl.getType() == Const.AclTypeEnum.MENU.getCode()){
            roleAclModuleTreeDto.setTitle(acl.getName()+"("+Const.AclTypeEnum.codeOf(acl.getType()).getValue()+")");
        }else{
            roleAclModuleTreeDto.setTitle(acl.getName());
        }
        roleAclModuleTreeDto.setParentId(acl.getAclModuleId());
        roleAclModuleTreeDto.setId(Integer.MAX_VALUE);
        return roleAclModuleTreeDto;
    }

    public static RoleAclModuleTreeDto adapter(AclModule aclModule){
        RoleAclModuleTreeDto roleAclModuleTreeDto = new RoleAclModuleTreeDto();
        BeanUtils.copyProperties(aclModule, roleAclModuleTreeDto);
        roleAclModuleTreeDto.setTitle(aclModule.getName()+"(不可选)");
        return roleAclModuleTreeDto;
    }

}
